package xyz.kongbai121.modules.sys.controller;

import xyz.kongbai121.common.utils.PageUtils;
import xyz.kongbai121.common.utils.Result;
import xyz.kongbai121.modules.sys.entity.SysDictTypeEntity;
import xyz.kongbai121.modules.sys.service.SysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;



/**
 * 字典类型
 *
 * @author ljq
 * @date 2021-11-08 17:36:53
 */
@Api(tags = "字典数据类型管理")
@RestController
@RequestMapping("/sys/sysdicttype")
public class SysDictTypeController {
    @Autowired
    private SysDictTypeService sysDictTypeService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表")
    @GetMapping("/list")
    @RequiresPermissions("sys:sysdicttype:list")
    public Result<PageUtils> list(@ApiParam(value = "当前页码", example = "0", required=false) @RequestParam(value = "curPage") Long curPage,
                                  @ApiParam(value = "每页显示条数", example = "0", required=false) @RequestParam(value = "pageSize") Long pageSize){

        Map<String, Object> params = new HashMap<>();
        params.put("page", curPage);
        params.put("limit", pageSize);
        PageUtils page = sysDictTypeService.queryPage(params);

        return Result.ok(page);
    }


    /**
     * 详情
     */
    @ApiOperation(value = "详情")
    @GetMapping("/info/{id}")
    @RequiresPermissions("sys:sysdicttype:info")
    public Result<SysDictTypeEntity> info(@ApiParam(value = "id", example = "0", required=true) @PathVariable("id") Long id){
		SysDictTypeEntity sysDictType = sysDictTypeService.getById(id);

        return Result.ok(sysDictType);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存")
    @PostMapping("/save")
    @RequiresPermissions("sys:sysdicttype:save")
    public Result save(@ApiParam(value = "实体", required=true) @RequestBody SysDictTypeEntity sysDictType){
		sysDictTypeService.save(sysDictType);

        return Result.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PutMapping("/update")
    @RequiresPermissions("sys:sysdicttype:update")
    public Result update(@ApiParam(value = "实体", required=true) @RequestBody SysDictTypeEntity sysDictType){
		sysDictTypeService.updateById(sysDictType);

        return Result.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    @RequiresPermissions("sys:sysdicttype:delete")
    public Result delete(@ApiParam(value = "id数组", required=true) @RequestBody Long[] ids){
		sysDictTypeService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

}
